<?php
/**
 *  Flvmeister
 *  a multi-format video transcoder class written in PHP5 
 *  Copyright (C) 2008  Marco Fischer <marco@flvmeister.com>
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by    
 *  the Free Software Foundation, either version 3 of the License, or
 *  any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 *
 */

require_once "Zend/Loader.php";
Zend_Loader::registerAutoload();

$db = Flvmeister::getDb( new Flvmeister_Config_Env() );

$select = $db->select()
             ->from( 'flvmeister_cronjobs' )
             ->where( 'status = ?', Flvmeister::STATUS_NEW );
             
$result = $db->fetchAll( $select );

foreach ($result as $row)
{
    $flvmeister = unserialize( $row[ 'flvmeister' ] );
    $job = unserialize( $row[ 'job' ] );
    
    if ( $flvmeister->worker( $job ) )
    {    
        $db->update( 'flvmeister_cronjobs', array('status' => Flvmeister::STATUS_FINISHED), 'id = ' . $row['id']  );
    } else 
    {
        $db->update( 'flvmeister_cronjobs', array('status' => Flvmeister::STATUS_ERROR ), 'id = ' . $row['id']  );
    }
}